<template>
    <div class="wrap">
        <div class="d-flex align-items-center">
            <label class="el-form-item__label">{{ $t('message.FlightControlSimulationDesignTool.parameter') }}：</label>
        </div>
        <div class="d-flex mt-2 align-items-center">
            <el-checkbox v-model="isExportSTL">
                {{ $t('message.FlightControlSimulationDesignTool.isExportSTL') }}
            </el-checkbox>
        </div>
        <div class="d-flex mt-2 align-items-center">
            <el-checkbox v-model="isExportXML">
                {{ $t('message.FlightControlSimulationDesignTool.isExportXML') }}
            </el-checkbox>
        </div>
        <div class="btn">
            <el-button type="primary" size="small" :disabled="isConfirm"
                       @click="confirm">{{ $t('message.FlightControlSimulationDesignTool.create') }}
            </el-button>
            <el-button size="small"
                       @click="cancel">{{ $t('message.FlightControlSimulationDesignTool.close') }}
            </el-button>

        </div>
    </div>
</template>
<script>

import DialogMixin from "../DialogMixin";
import {flightControlSimulationCommand} from "../../../command/FlightControlSimulationCommand";
import {measureCableCommand} from "../../../command/MeasureCableCommand";

export default {
    name: "FlightControlSimulationDesign",
    mixins: [DialogMixin],
    data() {
        return {
            isConfirm:false,
            isInit: false,
            files: [],
            errMsg: '',
            isExportSTL: true,
            isExportXML: true,
            importDisabled: true,
            fileLimitNum: 1,
            importModelXMLOptions: [{
                value: 0,
                label: '从约束新建',
                disabled:false,
            }, {
                value: 1,
                label: '从数据库读取',
                disabled:false,
            }],
            assembly: {},
            mateFeature: [],
            totalInsLength:0,
            percentage: 0,
            showProgress:false,
        }
    },
    mounted() {
        if (!this.isInit) {
            flightControlSimulationCommand.init(350, 350, 600, () => {
                flightControlSimulationCommand.clearAllHighLight();
                flightControlSimulationCommand.getAssemblyInfo((assembly, mateFeature) => {
                    this.assembly = {};
                    this.mateFeature = [];
                    this.assembly = assembly;
                    this.mateFeature = mateFeature;
                    this.totalInsLength = assembly.instanceTreeView.treeLength;
                    flightControlSimulationCommand.searchSavedXMLAssemInfo();
                });
                this.isInit = true;
            })
        }
    },
    methods: {
        changePluginContainerHeight() {
            flightControlSimulationCommand.changePluginContainerHeight({
                minWidth: this.$el.clientWidth,
                maxHeight: this.$el.clientHeight + 10
            });
        },
        confirm() {
            if (this.isExportXML){
                this.setXML();
            }
            if(this.isExportSTL){
                flightControlSimulationCommand.setIsExportSTL(true);
            }
        },
        cancel() {
            flightControlSimulationCommand.clearAllHighLight();
            flightControlSimulationCommand.closeActiveCmd();
        },
        setXML() {
            if (this.mateFeature.length) {
                //约束存在，直接创建xml
                flightControlSimulationCommand.openLoading('正在导出数据...');
                flightControlSimulationCommand.getSimulationInfo();
            } else {
                //约束不存在，根据数据库xml确定
                flightControlSimulationCommand.createXMLFromDataBase();
            }
        },
    },
    watch: {},
    computed: {
        isUpload() {
            return true;
        }
    }
}
</script>

<style scoped>
.wrap {
    font-size: 12px;
    color: #606266
}

.limit {
    color: red;
}

.progressBar{
    width: 100%;
}
</style>


